﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jinquantesthuiyuan_system
{
    public partial class EditPass : Form
    {
        public EditPass()
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox3.Text == textBox4.Text)
            {
                //密码相等的情况下执行下一步
                //连接数据库
                try
                {
                    string Con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=huiyuan.accdb";
                    OleDbConnection dbconn = new OleDbConnection(Con);
                    dbconn.Open();//建立连接

                    string s1 = "update `jq_admin` set `username` = '" + textBox2.Text + "',`password` = " + textBox4.Text + "";
                    OleDbCommand command = new OleDbCommand(s1, dbconn);
                    //command.ExecuteNonQuery();
                    int des = command.ExecuteNonQuery();
                    if (des > 0)//判断删除的状态
                    {
                        MessageBox.Show("修改成功，请从新运行本软件！");
                        Close();

                    }
                    else
                    {
                        MessageBox.Show("修改失败！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误提示：" + "\r\n" + ex);
                }
            }
            else
            {
                //密码不相等的情况不进行下一步
                MessageBox.Show("新密码不一致，请重试！");
                return;
            }
        }

        private void EditPass_Load(object sender, EventArgs e)
        {
            //加载界面的时候 获取管理账号到界面
            //string Con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=huiyuan.accdb";
            //try
            //{
            //    OleDbConnection dbconn = new OleDbConnection(Con);
            //    dbconn.Open();//建立连接
            //    OleDbDataAdapter inst = new OleDbDataAdapter("SELECT `username` FROM `jq_admin`", dbconn);//选择全部数据
            //    Console.WriteLine(textBox1.Text = "" + inst);
            //    //OleDbCommand command = new OleDbCommand(inst);
            //    dbconn.Close();//关闭连接
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("获取账户错误提示：" + "\r\n" + ex);
            //}
        }
    }
}
